/**
 * create by young (young2f@outlook.com) on 2024/4/21
 */
'use strict';
const base = require('../base/controllerBase');
const _service = 'storeService';

class StoreController extends base {
  //
  // async inbound() {
  //   const { ctx, service } = this;
  //   try {
  //     const { body } = ctx.request;
  //
  //     const model = {
  //       tenantCode: { type: 'string' },
  //       code: { type: 'string' },
  //       orderCode: { type: 'string' },
  //     };
  //
  //     ctx.validate(model, body);
  //
  //     const result = await service[_service].inbound(body);
  //     ctx.body = result;
  //     ctx.status = 200;
  //   } catch (e) {
  //     console.error(e);
  //     const _message = e && e.message ? e.message : this.ERROR_MSG;
  //     ctx.body = { status: 'error', message: _message, result: e };
  //     ctx.status = 200;
  //   }
  // }

  // async outbound() {
  //   const { ctx, service } = this;
  //   try {
  //     const { body } = ctx.request;
  //     const model = {
  //       tenantCode: { type: 'string' },
  //       code: { type: 'string' },
  //     };
  //
  //     ctx.validate(model, body);
  //     console.log('out bound', body);
  //     const result = await service[_service].outbound(body);
  //     ctx.body = result;
  //     ctx.status = 200;
  //   } catch (e) {
  //     console.error(e);
  //     const _message = e && e.message ? e.message : this.ERROR_MSG;
  //     ctx.body = { status: 'error', message: _message, result: e };
  //     ctx.status = 200;
  //   }
  // }
  async statistics() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
      };

      ctx.validate(model, body);
      console.log('out bound', body);
      const result = await service[_service].statistics(body);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }

  async assess() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
      };

      ctx.validate(model, body);
      console.log('store assess', body);
      const result = await service[_service].assess(body);
      console.log('store assess res', result);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }
  async findOne() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
      };

      ctx.validate(model, body);
      body.isDeleted = false;
      const result = await service[_service].findOne(body);

      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }

  async findMany() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
      };

      ctx.validate(model, body);
      body.isDeleted = false;

      const result = await service[_service].findMany(body);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }
  async desktop() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
      };

      ctx.validate(model, body);
      body.isDeleted = false;
      const result = await service[_service].desktop(body);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }
  async export() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
      };

      ctx.validate(model, body);
      const result = await service[_service].exportExcel(body);
      console.log('exporet', result);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }
}

module.exports = StoreController;
